<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function st()
{
	var str=document.getElementById("num").value;
	var str1=document.getElementById("aft");
	var rule=document.getElementsByName("Sort");
	var list=new Array();
	var i,j,count,temp;
	if (str==""){
		alert("请输入内容！")
		return;
	}
	list=str.match(/(-?\d+)(\.\d+)?/g);
	for(n in list){
		list[n]=Number(list[n]);
	}
	count=list.length;
	for(i=0;i<count;i++){
		for(j=i+1;j<count;j++){
			if(list[i]>list[j]){
				temp=list[i];
				list[i]=list[j];
				list[j]=temp;
			}
		}
	}
	if(rule.item(0).checked){
		str1.value=list;
	}
	else if(rule.item(1).checked){
		str1.value=list.reverse();
	}
	else{
		alert("请选择排序方式！")
	}
}
</script>
</head>

<body>
<form method="post" name="">
请输入一组数：<input type="text" id="num" /><br />
请选择升序或降序：<input type="radio" name="Sort" value="up" />升序<input type="radio" name="Sort" value="down" />降序<br />
<input type="button" onclick="st()" value="提交" /><br />
排序后：<input type="text" id="aft" />
</form>
</body>
</html>
